/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nite.gestures;

import com.primesense.NITE.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.OpenNI.GeneralException;
import org.OpenNI.IObservable;
import org.OpenNI.IObserver;

/**
 *
 * @author xvanek9
 */
public class CircleGesture extends AbstractGesture {
    PrimaryPointUpdateObserver obs;

    public PrimaryPointUpdateObserver getObs() {
        return obs;
    }

    public void setObs(PrimaryPointUpdateObserver obs) {
        this.obs = obs;
    }
    public CircleDetector init(){
        CircleDetector cd = null;
        try {
            cd = new CircleDetector();
            cd.getCircleEvent().addObserver(new CircleObserver());
            cd.getNoCircleEvent().addObserver(new NoCircleObserver());
            cd.setCloseEnough(30);
            obs = new PrimaryPointUpdateObserver();
            cd.getPrimaryPointUpdateEvent().addObserver(obs);
        } catch (GeneralException ex) {
            Logger.getLogger(CircleGesture.class.getName()).log(Level.SEVERE, null, ex);
        }
        return cd;
    }
    
    private class CircleObserver implements IObserver <CircleEventArgs>{
        @Override
        public void update(IObservable<CircleEventArgs> io, CircleEventArgs args) {
            //System.out.println("Circle " + args.getCircle().getRadius() + " this wide. " + args.getTimes() + " times.");
            if (args.getTimes() > 1){
                System.out.println("Circle " + args.getCircle().getRadius() + " this wide.");
            }
        }
    }
        
        private class NoCircleObserver implements IObserver <NoCircleEventArgs>{

        @Override
        public void update(IObservable<NoCircleEventArgs> io, NoCircleEventArgs args) {
            System.out.println("This is not a circle. Reason: " + args.getReason().name());
        }
        
        }
    
}
